<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style>
            * {
                padding: 0;
                margin: 0;
                list-style: none;
            }
            html,
            body {
                width: 100%;
                height: 100%;
                border: 1px solid black;
                overflow: hidden;
                box-sizing: border-box;
            }
            body {
                display: flex;
                justify-content: center;
                align-items: center;
            }
            .login {
                width: 60%;
                height: 500px;
            }
            #user {
                width: 100%;
                height: 50px;
                border: 1px solid black;
                font-size: 23px;
            }
            #pwd {
                width: 100%;
                height: 50px;
                border: 1px solid black;
                font-size: 23px;
            }

            #btn {
                width: 65%;
                height: 30px;
                text-align: center;
                line-height: 30px;
                font-size: 25px;
            }
        </style>
    </head>
    <body>
        <div class="login">
            <input type="text" placeholder="请输入用户名" id="user" />
            <br />
            <br />
            <input type="password" placeholder="请输入密码" id="pwd" />
            <br />
            <br />
            <button id="btn">登录</button>
            <a id="register">去注册？</a>
        </div>
    </body>
    <script src="axios.js"></script>
    <script>
        btn.onclick = () => {
            if (user.value == '' || pwd.value == '') {
                alert('清输入');
            } else {
                axios
                    .post('/login', {
                        user: user.value,
                        pwd: pwd.value,
                    })
                    .then(res => {
                        if (res.data.code == 1) {
                            alert(res.data.msg);
                            localStorage.setItem('user', user.value);
                            localStorage.setItem('pwd', pwd.value);
                            location.href = '/home';
                        } else {
                            alert(res.data.msg);
                        }
                    });
            }
        };
        register.onclick = () => {
            location.href = '/register';
        };
    </script>
</html>
